home *** CD-ROM | disk | FTP | other *** search
- From: sdouglas@armltd.co.uk (scott douglass)
- Message-ID: <sdouglas-1503960936190001@193.131.176.202>
- X-Original-Date: Fri, 15 Mar 1996 09:36:19 +0000
- Path: in1.uu.net!bounce-back
- Date: 15 Mar 96 13:16:10 GMT
- Approved: fjh@cs.mu.oz.au
- Newsgroups: comp.std.c++
- Subject: Re: No way to define some extern consts?
- Organization: Apple Computer, Inc.
- References: <sdouglas-1403961511440001@193.131.176.202> <4iat2h$pk5@clarknet.clark.net>
- X-Newsreader: Yet Another NewsWatcher 2.0.2
- X-Auth: PGPMoose V1.1 PGP comp.std.c++
- iQBFAgUBMUltqOEDnX0m9pzZAQFtiwF+PE4cum8+fec3eIU8/df0k9Yu83zPbEVl
- jawL/VNZ89/40G9MCRPu/Y6ImWR0dY7i
- =DS/a
-
- In article <4iat2h$pk5@clarknet.clark.net>, gusty@clark.net (Harlan
- Messinger) wrote:
-
- : scott douglass (sdouglas@armltd.co.uk) wrote:
- : : Hello all,
- : :
- : : Given a class type with only a no-argument contstrutor:
- : :
- : : struct T { T(); /* ... */ }; // assume no other ctors
- : :
- : : Is there any way to define an extern const object of class T?
- :[...]
- : You'll declare
- :
- : extern const T t2;
- :
- : in the header file, but define
- :
- : const T t2;
- :
- : as a global non-static object in the one source file in which you want it
- : to reside.
-
- Thanks. As you mention and Geert-Jan Giezeman pointed out in private
- e-mail, the key here is that the definition can be accomplished by having
- both and extern declaration and a definition the same translation unit:
-
- extern const T t; // declaration
- const T t; // definition, still extern
-
- You can't do it in one declaration but it's not hard after all.
- --scott
- ---
- [ comp.std.c++ is moderated. To submit articles: try just posting with ]
- [ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
- [ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
- [ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
- [ Comments? mailto:std-c++-request@ncar.ucar.edu ]
-